package com.lawliet.example.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lawliet.example.model.User;
import com.lawliet.example.repository.UserMapper;
import com.lawliet.example.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Service;

@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IUserService {


    @Autowired
    private PasswordEncoder passwordEncoder;

    @Override
    public void registerUser(User user) {
        user.setPassword(passwordEncoder.encode(user.getPassword()));
       this.save(user);
    }


    @Override
    //根据用户名查询用户
    public User getUserByUsername(String username) {
        LambdaQueryWrapper<User> con = new LambdaQueryWrapper<>();
        con.eq(User::getUsername,username);
        User userInfo = getOne(con);

        return userInfo;
    }
}